package cn.wolfcode.web.controller;

import cn.wolfcode.qo.JsonResult;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IPermissionService;
import cn.wolfcode.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("/list")
    public String list(QueryObject qo, Model model){
        model.addAttribute("pageInfo",permissionService.selectList(qo));
        return "permission/list";
    }

    @RequiredPermission(name="权限加载",expression = "permission.reload")
    @RequestMapping("/reload")
    @ResponseBody
    public JsonResult reload(){
        //加载所有controller中所有贴了RequiredPermission 注解，取出注解上的name 和 expression,封装成Permission，保存到数据库中
        permissionService.reload();
        return new JsonResult();
    }

}
